<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>24-自定义指令-带参数</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
      .box {
        width: 100px;
        height: 100px;
        border: 1px solid #ccc;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="box" v-color="info">盒子</div>
    </div>
    <script>
      Vue.directive('color', {
        bind: function (el, bind) {
          console.log(el);
          console.log(bind.value.color);
          el.style.backgroundColor = bind.value.color;
        },
      });
      var vm = new Vue({
        el: '#app',
        data: {
          info: {
            color: 'skyblue',
          },
        },
        methods: {},
      });
    </script>
  </body>
</html>
